
<!DOCTYPE html>
<html lang="en" class="app">
    <head>
        <title>Agent Management | <?php echo SITENAME; ?></title>
        <meta name="description" content="" />
        <?php  fnGetHeader(); ?>
        
         <link rel="stylesheet" href="<?php  echo SITEURL.VIEW; ?>js/datepicker/datepicker.css">
          </head>
    <body>
        <?php fnGetSidebar(); ?>
        <section id="content">
            <section class="vbox">
                <section class="scrollable padder">
                    <div class="m-b-md"> <?php echo @$this->noti; ?>
                        <h3 class="m-b-none"><?php
                            if (GET('action') == 'edit') {
                                echo 'Edit';
                            } else if (GET('action') == 'add') {
                                echo 'Add';
                            } else if (GET('action') == 'view') {
                                echo 'All';
                            }
                            ?> Agent 
                            <?php
                            if (GET('action') == 'view') {
                                echo 'Report';
                            }
                            ?>
                        </h3>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">

                            <?php if (GET('action') == "add" || GET('action') == "edit") { ?>
                                <section class="panel panel-default">
                                   
                                    
                                    <header class="panel-heading font-bold">Agent</header>
                                    <?php
                                            if (count($this->ErrorMessage) > 0):
                                                foreach ($this->ErrorMessage as $key => $value):
                                                    ?>
                                                    <div id="msg" class="alert alert-danger" style="opacity: 0.846072;">
                                                        <button data-dismiss="alert" class="close" type="button">×</button>
                                                        <i class="fa fa-ok-sign"></i> <?php echo $value; ?>
                                                    </div>
                                                <?php endforeach;
                                            endif;
                                            ?>  
                                    <div class="panel-body">
                                        <form class="bs-example form-horizontal" method="post" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">Name</label>
                                                <div class="col-lg-10">
                                                    <input class="form-control" placeholder="Agent Name" name="ag_name" type="text" value="<?php
                                                    if($_POST){
                                                        echo $this->ag_name;
                                                    }else if (GET('editUid')) {
                                                        echo stripslashes($this->editrow['ag_name']);
                                                    }
                                                    ?>" required>
                                                </div>
                                            </div>
                                            
                                             <div class="form-group">
                                                <label class="col-lg-2 control-label">Email</label>
                                                <div class="col-lg-10">
                                                    <input class="form-control" placeholder="Agent Email" name="ag_email" type="text" value="<?php
                                                    if($_POST){
                                                        echo $this->ag_email;
                                                    }else if (GET('editUid')) {
                                                        echo stripslashes($this->editrow['ag_email']);
                                                    }
                                                    ?>" required>
                                                </div>
                                            </div>
                                            
                                            
                                             <div class="form-group">
                                                <label class="col-lg-2 control-label">Contact Number</label>
                                                <div class="col-lg-10">
                                                    <input class="form-control" placeholder="Contact Number" name="ag_phone_no" type="text" value="<?php
                                                    if($_POST){
                                                        echo $this->ag_phone_no;
                                                    }else if (GET('editUid')) {
                                                        echo stripslashes($this->editrow['ag_phone_no']);
                                                    }
                                                    ?>" required>
                                                </div>
                                            </div>
                                            
                                            
                                            
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">Status</label>
                                                <div class="col-lg-10">
                                                    <select required="" id="ag_status" class="form-control" name="ag_status">
                                                        <option value="">--Select Status--</option>
                                                        <option value="1" <?php
                                                        if($_POST){
                                                            if ($this->ag_status == 1) {
                                                                echo 'selected';
                                                            }
                                                        }
                                                        if (GET('editUid')) {
                                                            if ($this->editrow['ag_status'] == 1) {
                                                                ?> selected <?php
                                                                    }
                                                                }
                                                                ?>>Active</option>
                                                        <option value="0" <?php
                                                        if($_POST){
                                                            if ($this->ag_status == 0) {
                                                                echo 'selected';
                                                            }
                                                        }if (GET('editUid')) {
                                                            if ($this->editrow['ag_status'] == 0) {
                                                                ?> selected <?php
                                                                    }
                                                                }
                                                                ?>>Inactive</option>
                                                    </select>
                                                </div>
                                            </div>


                                            <!---- Button -->
                                            <div class="form-group">
                                                <div class="col-lg-offset-2 control-label col-lg-10">
                                                    <?php
                                                    if (GET('editUid')) {
                                                        echo '<input type="hidden" name="editUid" value="' . GET('editUid') . '">';
                                                    }
                                                    ?>
                                                    <button type="submit" name="submit" value="Submit" class="btn btn-s-md btn-primary ">
                                                        <?php
                                                        if (GET('editUid')) {
                                                            echo 'Update';
                                                        } else {
                                                            echo "Create";
                                                        }
                                                        ?>
                                                    </button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </section>
                            </div>
                        </div>

                        <?php
                    } else if (GET('action') == "view") {
                        ?>

                        <section class="panel panel-default">
                            <header class="panel-heading"> All Agent </header>
                            <div class="row text-sm wrapper">
                                <form action="" method="get">
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <input class="input-sm form-control" placeholder="Search" name="q" type="text">
                                            <span class="input-group-btn">
                                                <input type="hidden" name="action" value="view">
                                                <button class="btn btn-sm btn-default" type="submit" name="search" value="search">Go!</button>
                                            </span> </div>
                                    </div>
                                </form>
                            </div>
                            <form action="" method="post">
                                <div class="table-responsive">
                                    <table class="table table-striped b-t b-light text-sm">
                                        <thead>
                                            <tr>
                                                <th width="20"><input type="checkbox"></th>
												<th class="th-sortable" data-toggle="class">Agent ID </th>
                                                <th class="th-sortable" data-toggle="class">Agent Name </th>
                                                <th class="th-sortable" data-toggle="class">Agent Email </th>
                                                <th class="th-sortable" data-toggle="class">Contact Number </th>
                                                <th>Last Modify</th>
                                                <th>Modify By</th>
                                                <th width="60"></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php ?>
                                            <?php
                                            if (count($this->PagingNationFetch) > 0) {
                                                foreach ($this->PagingNationFetch as $PagingNationFetch) {
                                                    ?>
                                                    <tr>
                                                        <td><input name="ag_id[]" value="<?php echo $PagingNationFetch['ag_id'] ?>" type="checkbox"></td>
                                                        <td><?php echo stripslashes($PagingNationFetch['ag_id']) ?></td>
							<td><?php echo stripslashes($PagingNationFetch['ag_name']) ?></td>
                                                        <td><?php echo stripslashes($PagingNationFetch['ag_email']) ?></td>
                                                        <td><?php echo stripslashes($PagingNationFetch['ag_phone_no']) ?></td>
                                                        <td><?php echo $PagingNationFetch['ag_updatedate'] ?></td>
                                                        <td><?php echo getAdmin($PagingNationFetch['LastModifyBy']); ?></td>
                                                        <td><a href="<?php echo URL ?>agent/?action=edit&editUid=<?php echo $PagingNationFetch['ag_id'] ?>"><i class="fa fa-edit"></i></a>
                                                        <!--<a href="<?php echo SITEURL ?><?php echo $PagingNationFetch['ag_alias'] ?>" target="_blank"><i class="fa fa-eye"></i></a>
                                                            -->
                                                        </td>
                                                    </tr>
                                                    <?php
                                                }
                                            } else {
                                                ?>
                                                <tr>
                                                    <td colspan="5" style="text-align: center"><b>No Record Found</b></td>
                                                </tr>
                                            <?php } ?>



                                        </tbody>
                                    </table>
                                </div>
                                <footer class="panel-footer">
                                    <div class="row">
                                        <div class="col-sm-4 hidden-xs">

                                            <button type="submit" name="delete" onClick="return confirm('Are you sure to delete?');" class="btn btn-sm btn-default">Delete</button>
                                        </div>

                                        <div class="col-sm-8 text-right text-center-xs">
                                            <?php
                                            if (count($this->PagingNationFetch) > 0) {
                                                echo pagination($this->statement, $this->limit, $this->page, '?', $this->oldData);
                                            }
                                            ?>
                                        </div>

                                    </div>
                                </footer>
                            </form>
                        </section>

                    <?php } else { ?>

                        <section class="panel panel-default">
                            <header class="panel-heading font-bold">Agent Report</header>
                            <div class="panel-body"> 
                               
                                 <?php
                                            if (count($this->ErrorMessage) > 0):
                                                foreach ($this->ErrorMessage as $key => $value):
                                                    ?>
                                                    <div id="msg" class="alert alert-danger" style="opacity: 0.846072;">
                                                        <button data-dismiss="alert" class="close" type="button">×</button>
                                                        <i class="fa fa-ok-sign"></i> <?php echo $value; ?>
                                                    </div>
                                                <?php endforeach;
                                            endif;
                                            ?>  
                                
                                <form action="" method="get">
                                    
                                   <!-- <div class="form-group">
                                        <label class="col-lg-2 control-label">Agent</label>
                                        <div class="col-lg-5">
                                            <select name="ag_id" id="" class="form-control" required style="width:50%;">
                                                <option value="">Select Agent</option>
                                                <?php foreach($this->agentArray as $agent_key => $agent_value):?>
                                                <option <?php if($this->agent_id == $agent_value['ag_id']): echo "selected";endif; ?> value="<?php echo $agent_value['ag_id']?>"><?php echo $agent_value['ag_name']; ?></option>
                                                <?php endforeach; ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <br/>-->
                                    <div class="form-group">
                                        <label class="col-lg-2 control-label">Start Date</label>
                                        <div class="col-lg-5">
                                            <input class="form-control datepicker" placeholder="Start Date" name="start_date" id="start_date" type="text" value="<?php echo $this->start_date ?>">
                                        </div>
                                    </div>

                                    <div class="clearfix"></div>
                                    <br/>
                                    <div class="form-group">
                                        <label class="col-lg-2 control-label">End Date</label>
                                        <div class="col-lg-5">
                                            <input class="form-control datepicker" placeholder="End Date" name="end_date" id="end_date" type="text" value="<?php echo $this->end_date ?>">
                                        </div>
                                    </div>
                                    <div class="clearfix"></div>
                                    <br/>
                                    <input type="hidden" name="action" value="report"/>
                                    <button type="submit" name="submit_report" value="Submit" class="btn btn-s-md btn-primary ">
                                        Submit
                                    </button>
                                </form>
                            </div>


                            <div class="table-responsive">
                                <table class="table table-striped b-t b-light text-sm">
                                    <thead>
                                        <tr>
                                            <th width="20">&nbsp;</th>
                                            <th>Agent Name </th>
                                            <th>Total Transaction</th>
											<th>Total Amount </th>
                                           <!-- <th>Payment Type </th>
                                            <th>Payment Amount</th>
                                            <th>Date</th>-->
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php if(count($this->fetchAgentOrderData) > 0):
                                            foreach($this->fetchAgentOrderData as $ag_key =>$ag_value):?>
                                            <tr>
                                            <td></td>
                                            <td><?php  echo $ag_value['ag_name']?></td>
                                            <td><?php  echo $ag_value['payment_count'] ?></td>
                                            <td><?php  echo "$ ".$ag_value['total_amount']?></td>
                                            <!--<td><?php  echo $ag_value['pt_total_amount']?></td>
                                            <td><?php  echo date('Y-m-d',strtotime($ag_value['pt_createDate']))?></td>-->
                                        </tr>
                                          <?php   endforeach; 
                                          else:?>
                                        <tr>
                                            <td colspan="3" style="text-align: center">No record found</td>
                                        </tr>
                                        <?php endif;?>
                                        
                                    </tbody>
                                </table>
                            </div>
<div class="col-sm-8 text-right text-center-xs">
                                            <?php
                                            if (count($this->fetchAgentOrderData) > 0) {
                                                echo pagination($this->statement, $this->limit, $this->page, '?', $this->oldData);
                                            }
                                            ?>
                                        </div>


                        </section>


                    <?php } ?>
                </section>
            </section>
        </section>
        <?php fnGetFooter(); ?>
        <!-- file input --> <script src="<?php echo TEMPLATE; ?>js/file-input/bootstrap-filestyle.min.js" cache="false"></script>
        <script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>

        <script>
                                            function GetKeyword()
                                            {
                                                $("#searchTags").val($("#keywords").val());
                                            }
        </script>
    </body>
</html>

<script src="<?php echo SITEURL.VIEW; ?>js/datepicker/bootstrap-datepicker.js"></script>
<script type="text/javascript">
  // When the document is ready
  $(document).ready(function () {

      $('#start_date').datepicker({
          format: "yyyy-mm-dd"
      }).on('changeDate', function(e){
        $(this).datepicker('hide');
      }); 
      
       $('#end_date').datepicker({
          format: "yyyy-mm-dd"
      }).on('changeDate', function(e){
        $(this).datepicker('hide');
      }); 

  });
</script>
   